package com.example.demo.servicemanage.service.impl;

import com.example.demo.servicemanage.mapper.ServiceMapper;
import com.example.demo.servicemanage.service.ServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(propagation = Propagation.REQUIRED)
public class ServiceServiceImpl implements ServiceService {
    @Autowired
    private ServiceMapper serviceMapper;


    /**
         * @Description 新增维修记录
         * @Author zhangxue
         * @Date 11:18 2018/7/12
         * @Param
         * @retrun
         **/
    @Override
    public Map<String, Object> saveService(Map<String, Object> param) {
        int i = serviceMapper.saveServiceMapper(param);
        Map<String,Object> resultMap = new HashMap<String, Object>();
        if(i==1){
            resultMap.put("status","1");
        }else{
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            resultMap.put("status","0");
        }
        return resultMap;
    }

    /**
     * @Description 编辑维修记录
     * @Author zhangxue
     * @Date 11:18 2018/7/12
     * @Param
     * @retrun
     **/
    @Override
    public Map<String, Object> editService(Map<String, Object> param) {
        int i = serviceMapper.editServiceMapper(param);
        Map<String,Object> resultMap = new HashMap<String, Object>();
        if(i==1){
            resultMap.put("status","1");
        }else{
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            resultMap.put("status","0");
        }
        return resultMap;
    }

    /**
     * @Description 删除维修记录
     * @Author zhangxue
     * @Date 11:18 2018/7/12
     * @Param
     * @retrun
     **/
    @Override
    public Map<String, Object> delService(Map<String, Object> param) {
        int i = serviceMapper.delServiceMapper(param);
        Map<String,Object> resultMap = new HashMap<String, Object>();
        if(i==1){
            resultMap.put("status","1");
        }else{
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            resultMap.put("status","0");
        }
        return resultMap;
    }

    /**
         * @Description 查询所有维修记录
         * @Author zhangxue
         * @Date 11:00 2018/11/13
         * @Param
         * @retrun
         **/
    @Override
    public Map<String, Object> queryAllService(Map<String, Object> param) {
        List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
        resultList = serviceMapper.queryAllService(param);
        Map<String,Object> resultMap = new HashMap<String, Object>();
        resultMap.put("data",resultList);
        return resultMap;

    }



}
